package hot_100;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: Darven
 * @createTime: 2025-10-04  22:46
 * @description: TODO
 */
public class P46 {

    private List<List<Integer>> ans=new ArrayList<>();
    private List<Integer> res=new ArrayList<>();
    public List<List<Integer>> permute(int[] nums) {
        int length = nums.length;
        boolean[] used=new boolean[length];
        find(nums, used);
        return ans;
    }

    private void find(int[] nums,boolean[] used){
        if(res.size()==nums.length){
            ans.add(new ArrayList<>(res));
            return;
        }
        for (int i=0;i<nums.length;i++){
            if(used[i]){
                continue;
            }

            used[i]=true;
            res.add(nums[i]);
            find(nums,used);
            res.removeLast();
            used[i]=false;
        }

    }
}
